package com.yeyks.app.controller.base.config;

import com.yeyks.common.ajax.AjaxResponseBody;
import com.yeyks.common.utils.ArgumentsCheckUtil;
import com.yeyks.common.utils.UnicodeUtils;
import com.yeyks.config.service.DocInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author fuchangshuai
 * @date 2019/3/26 4:27 PM
 */
@Api(tags = "文档接口", description = "文档")
@Slf4j
@RestController("appDocInfoController")
@RequestMapping(value = "/app/doc")
public class DocInfoController {
    @Autowired
    private DocInfoService docInfoService;

    /**
     * 用户获取文档列表
     *
     * @param parent
     * @param keyword
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ApiOperation(value = "用户获取文档列表", notes = "用户获取文档列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "parent", value = "是否是分类，默认0内容，1分类", defaultValue = "0", dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "keyword", value = "关键字", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pageNum", value = "当前页", defaultValue = "1", dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "每页个数", defaultValue = "10", dataType = "int")
    })
    @PostMapping(value = "/list")
    public AjaxResponseBody<Map<String, Object>> docList(
            @RequestParam(name = "parent", defaultValue = "0") Integer parent,
            @RequestParam(name = "keyword", required = false) String keyword,
            @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        if (ArgumentsCheckUtil.notEmpty(keyword)) {
            keyword = UnicodeUtils.unicodeToString(keyword);
        }
        Map<String, Object> map = docInfoService.selectDocByPage(parent, keyword, pageNum, pageSize);
        return AjaxResponseBody.success(map);
    }
}
